<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>5.展开语法真的好用啊</title>
</head>

<body>
  <script>
    //数组合并
    let arr = ['hdcms', 'houdunren'];
    let hd = ['js', 'css'];

    for (const value of hd) {
      arr.push(value);
    }
    console.log(arr); //['hdcms', 'houdunren', 'js', 'css']
    //展开语法 合并数组
    arr = ['hdcms', 'houdunren'];
    console.log([...arr, ...hd]); //['hdcms', 'houdunren', 'js', 'css']
    //展开语法可以接收任意数量的参数
    function sum(...args){
      console.log(args);
      return args.reduce((s,v)=> {
        return s+=v;
      })
    }
   console.log(sum(1,2,34,54,5));
   //作为函数参数使用
   function hd ([a, b]) {
      console.log(a, b);
    }
    hd(['后盾人', 'hdcms']);
  </script>
</body>

</html>